﻿/********************************************************************************************
 * 文件名称:	CommonMenu.cs
 * 设计人员:	严(yanxianghui@gmail.com)
 * 设计时间:	2009-03-16
 * 功能描述:	信息结构
 * 注意事项:	
 * 版权所有:	Copyright (c) 2009, Fujian SIRC
 * 修改记录: 	修改时间		人员		修改备注
 *				    ----------		------		-------------------------------------------------
 *
 ********************************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using Shanfree.SharpMovie.Model;
using Shanfree.SharpMovie.IDAL;
using Shanfree.SharpMovie.DALFactory;
using Shanfree.Framework.Utility;

namespace Shanfree.SharpMovie.BLL
{
    /// <summary>
    /// 栏目信息的读取
    /// </summary>
    public class Menu
    {
        private static readonly IMenu dal = DataAccess.CreateMenu();

        #region IMenu 成员
        /// <summary>
        /// 根据根节点ID获取栏目树
        /// </summary>
        /// <param name="parentID">根节点ID，默认为-1</param>
        /// <param name="isAll">true:显示所有栏目；false:显示首页栏目</param>
        /// <returns></returns>
        public TreeNodeInfo<MenuInfo> GetMenuTree(string parentID, bool isAll)
        {
            if (string.IsNullOrEmpty(parentID))
            {
                throw new ArgumentNullException("parentID");
            }
            return dal.GetMenuTree(parentID, isAll);
        }

        /// <summary>
        /// 获取子栏目列表
        /// </summary>
        /// <param name="parentID">父栏目ID</param>
        /// <returns></returns>
        public IList<MenuInfo> GetSubMenuList(string parentID)
        {
            if (string.IsNullOrEmpty(parentID))
            {
                throw new ArgumentNullException("parentID");
            }
            return dal.GetSubMenuList(parentID);
        }

        /// <summary>
        /// 添加栏目
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="parentID">父栏目ID</param>
        /// <param name="sortNum">排序号</param>
        /// <param name="isShow">是否显示在主页栏目</param>
        /// <param name="url">显示链接</param>
        /// <param name="isCustomer">自定义栏目</param>
        /// <param name="isExtendUrl">外部链接</param>
        /// <returns>主键</returns>
        public string Add(string name, string parentID, int sortNum, bool isShow, string url, bool isCustomer, bool isExtendUrl)
        {
            if (string.IsNullOrEmpty(parentID))
            {
                throw new ArgumentNullException("parentID");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            MenuInfo mInfo = new MenuInfo();
            mInfo.IsCustomer = isCustomer;
            mInfo.IsExtendUrl = isExtendUrl;
            mInfo.IsShow = isShow;
            mInfo.Name = name;
            mInfo.ParentID = parentID;
            mInfo.SortNum = sortNum;
            mInfo.Url = url;
            return dal.Add(mInfo);
        }

        /// <summary>
        /// 删除栏目
        /// </summary>
        /// <param name="id">栏目主键</param>
        public void Delelte(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }
            MenuInfo mInfo = new MenuInfo();
            mInfo.ID = id;
            dal.Delete(mInfo);
        }

        /// <summary>
        /// 更新栏目信息
        /// </summary>
        /// <param name="id">栏目主键</param>
        /// <param name="name">名称</param>
        /// <param name="parentID">父栏目ID</param>
        /// <param name="sortNum">排序号</param>
        /// <param name="isShow">是否显示在主页栏目</param>
        /// <param name="url">显示链接</param>
        /// <param name="isExtendUrl">是否为外部链接</param>
        /// <param name="isCustomer">自定义栏目</param>
        public void Update(string id, string name, string parentID, int sortNum, bool isShow, string url, bool isExtendUrl, bool isCustomer)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (string.IsNullOrEmpty(parentID))
            {
                throw new ArgumentNullException("parentID");
            }
            MenuInfo mInfo = new MenuInfo();
            mInfo.ID = id;
            mInfo.IsCustomer = isCustomer;
            mInfo.IsExtendUrl = isExtendUrl;
            mInfo.IsExtendUrl = isShow;
            mInfo.Name = name;
            mInfo.ParentID = parentID;
            mInfo.SortNum = sortNum;
            mInfo.Url = url;
            dal.Update(mInfo);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MenuInfo GetByID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }
            MenuInfo mInfo = dal.GetByID(id);
            return mInfo;
        }

        #endregion


    }
}